# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:mybro04.py
@Time:2022/3/1 10:15

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""
from mybro03 import Mybro

bro=Mybro()
bro.switchquery()
zd="企业一套表统计调查制度(2022)"
zqlist=bro.getyjnopts(zd)
print(zqlist)
with open('mulu.csv','w',encoding='u8') as f:
    #f.write(zd)
    f.write('')
i=1
for zq in zqlist:
    j=1
    bblist,bbhb=bro.getbblist1(zd,zq)
    #print(bblist)
    print(bbhb)
    for bb in bbhb:
        k=1
        bb,cxmllist=bro.getquery1(bb)
        #print(f'制度：{zd},周期：{zq},报表：{bb},查询目录：{cxml}')
        for cxml in cxmllist:
            if j<10:
                if k<10:
                    print(f'0,{zd},{i},{zq},{i}0{j},{bb},{i}0{j}0{k},{cxml}')
                else:
                    print(f'0,{zd},{i},{zq},{i}0{j},{bb},{i}0{j}{k},{cxml}')
            else:
                if k < 10:
                    print(f'0,{zd},{i},{zq},{i}0{j},{bb},{i}0{j}0{k},{cxml}')
                else:
                    print(f'0,{zd},{i},{zq},{i}0{j},{bb},{i}0{j}{k},{cxml}')

            with open('mulu.csv','a',encoding='u8') as f:
                if j < 10:
                    if k < 10:
                        f.write(f'0,{zd},{i},{zq},{i}0{j},{bb},{i}0{j}0{k},{cxml}')
                        f.write('\n')
                    else:
                        f.write(f'0,{zd},{i},{zq},{i}0{j},{bb},{i}0{j}{k},{cxml}')
                        f.write('\n')
                else:
                    if k < 10:
                        f.write(f'0,{zd},{i},{zq},{i}0{j},{bb},{i}0{j}0{k},{cxml}')
                        f.write('\n')
                    else:
                        f.write(f'0,{zd},{i},{zq},{i}0{j},{bb},{i}0{j}{k},{cxml}')
                        f.write('\n')
                # f.write(f'0,{zd},{i},{zq},{j},{bb},查询目录,{cxmllist}')
                # f.write('\n')
            k+=1
        j+=1
    i+=1
bro.closewindow()